'use strict';
/**
 * iceView v1.0.1
 * MIT License By www.iceui.cn
 * 作者：ICE
 * ＱＱ：308018629
 * 官网：www.iceui.cn
 * 说明：版权完全归iceui所有，转载和使用请注明版权
 * -------------------------------------------------------------
 * 模板引擎
 * iceView 2020-06-28
 */
var ice = ice || {};
ice.view = function(options, msgList) {
	// var reg = /\{\{(([^}][\s\S])*)\}\}/g;
	var reg = /\{\{([\w\W]*?)\}\}/g;
	//克隆对象
	function cloneObj(obj){
	    if (typeof obj !== 'object') return obj;
	    let newObj = Array.isArray(obj) ? [] : {};
	    for (let key in obj) {
	    	newObj[key] = cloneObj(obj[key]);
	    }
	    return newObj;
	}
	//去重
	function ra(arr) {
		if(!arr) return [];
		const a = [],b = {};
		for (const i of arr) {
			if (!b[i]) {
				a.push(i);
				b[i] = 1;
			}
		}
		return a
	}
	function isObject (obj) {
		return obj !== null && typeof obj === 'object'
	}
	function isObjectEqual (a, b) {
		var objectA = isObject(a),objectB = isObject(b);
		if (objectA && objectB) {
		  try {
			return JSON.stringify(a) === JSON.stringify(b)
		  } catch (e) {
			return a === b
		  }
		} else if (!objectA && !objectB) {
		  return String(a) === String(b)
		} else {
		  return false
		}
	}
	function toDom(html) {
		if (typeof html === 'string') {
			var temp = document.createElement('div');
			temp.innerHTML = html;
			var frag = document.createDocumentFragment();
			while (temp.firstChild) {
				frag.appendChild(temp.firstChild);
			}
			return frag;
		} else {
			return html;
		}
	};

	//消息队列
	function msg() {
        this.list = {};
    }
    msg.prototype = {

        addList: function (node,keys) {
			var that = this;
			//将k变量名称处理成这种
			//list[0].child
			//list[0]
			//list
			var arr = keys.split('');
			var str = '';
			var keyArr = [];
			for(var i=0;i<arr.length;i++){
				var s = arr[i];
				if(s == '[' || s == '.'){
					keyArr.push(str);
				}
				str += s;
			}
			keyArr.push(str);
			for1:
			for(var i=0;i<keyArr.length;i++){
				var key = keyArr[i];
				//防止添加重复的消息队列
				this.list[key] = this.list[key] ? this.list[key] : [];
				//节点为for，删掉所有相关的
				for(var s=0;s<this.list[key].length;s++){
					if(node.key === 'i-for' && this.list[key][s].v.indexOf(key) === 0){
						for3:
						for(var a=0;a<node.node.itemNode.length;a++){
							if(node.node.itemNode[a].contains(this.list[key][s].node)){
								// console.log('节点为for，删掉所有相关的：', key, this.list[key][s].v)
								this.list[key].splice(s,1);
								s--;
								break for3;
							}
						}
					}
				}
				
				for(var s=0;s<this.list[key].length;s++){
					if(node.key !== 'i-for' && this.list[key][s].key === 'i-for' && keys.indexOf(key) === 0){
						// console.log('存在for，不添加该队列：',key,keys)
						continue for1;
					}
					if(
						this.list[key][s].node == node.node && 
						this.list[key][s].key == node.key && 
						this.list[key][s].value == node.value
					){
						continue for1;
					}
				}
				this.list[key].push(node);
			}
        },
        update: function (key) {
        	// console.log('更新列队值', key)
        	if(this.list[key] && this.list[key].length){
        		this.list[key].forEach(function (node) {
	                node.update();
	            });
        	}
        },
        //删除某个节点的所有消息列队
        delList: function(node){
        	if(!node) return;
        	var that = this;

			//清除该节点下的所有节点消息列队
			var arr = [];
			!function eachNode(e){
				arr.push(e);
				e = e.childNodes;
				if (e.length) {
					for (var i = 0; i < e.length; i++) {
						eachNode(e[i]);
					}
				}
			}(node);

			for(var s=0;s<arr.length;s++){
				for(var key in that.list){
					for(var i=0;i<that.list[key].length;i++){
						//这里需要考虑到if和for的占位节点，被存储在hide中
						if(that.list[key][i].node == arr[s] || that.list[key][i].node.hide == arr[s]){
							that.list[key].splice(i,1);
							if(!that.list[key].length){
								delete that.list[key];
								break;
							}
						}
					}
				}
			}
			//删除页面上的元素
			if(node.parentNode)node.parentNode.removeChild(node);
        }
    };
	function iceView(options,msgList) {
		var that = this;
        this.data = options;
        this.msg = msgList ? msgList : new msg();
        this.el = document.getElementsByClassName('iceView');
        if(!this.el.length) return;
		this.el = this.el[0];
        //存储复选框的值
        this.checkbox = [];
        //保存数据所有key
        this.dataKey = [];
        Object.keys(options).forEach((k)=>{
        	if(k[0]=='$'){
        		throw "iceView：声明变量或方法第一个字符不能为$";
        	}
        	this.dataKey.push(k);
        });
        //备份数据，不会被监听
        this.datas = cloneObj(options);
        //劫持数据
        this.kidnap(options);

		//创建div
		if(this.el.tagName == 'TEMPLATE'){
			var div = document.createElement('div');
			div.innerHTML = this.el.innerHTML;
			this.el.parentNode.insertBefore(div,this.el);
			this.el = div;
		}
		this.msg.node = this.el;
		
		//遍历所有节点
		this.eachNode(this.el);

        //初始化完成，执行回调
		this.data.set = function(json){
			for(var key in json){
				that.data[key] = cloneObj(json[key]);
			}
			that.kidnap(that.data)
		}
		this.data.change = this.data.change ? this.data.change : function(){};
        this.data.onload && this.data.onload.bind(this.data)(this.data,this.msg);
        return this;
    }
    iceView.prototype = {
    	kidnap :function(data,keyArr = []){
    		if (typeof data !== 'object') {
	            return;
	        }
			if(Array.isArray(data)){
				this.reactiveArrayProto(data,keyArr);
			}
			var len = data.length;
	        Object.keys(data).forEach((key)=>{
	        	var keyList = cloneObj(keyArr);

				var list = cloneObj(keyList);
				if(len){
					list[list.length-1] = list[list.length-1]+'['+key+']';
				}else{
					list.push(key);
				}
	            this.reactive(data, key, data[key], list);
	        });

    	},
    	//遍历对象数据
	    eachData: function (data,keyList = []) {
			if(Array.isArray(data)){
				this.reactiveArrayProto(data, keyList);
			}
			var len = data.length;
	        Object.keys(data).forEach((key)=>{
	        	var list = cloneObj(keyList);
				if(len){
					list[list.length-1] = list[list.length-1]+'['+key+']';
				}else{
					list.push(key);
				}
				
	            this.reactive(data, key, data[key],list)
	        });
	    },
		//劫持对象属性setter、getter
	    reactive: function (data, key, val, keyList) {
	    	var keys = keyList.join('.');
	        var that = this;
	        Object.defineProperty(data, key, {
			    enumerable: true,
			    configurable: true,
	            get: function () {
	                return val;
	            },
	            set: function (newVal) {
	                if (newVal === val) {
	                    return;
	                } else {
						that.data.change && that.data.change.call(that.data);
	                    val = newVal;
	                    that.datas = cloneObj(that.data);
	                    that.kidnap(newVal,keyList); //劫持新数据
	                    that.msg.update(keys); //发出通知
	                }
	            }
	        });

	        //递归
	        if(typeof data[key] == 'object') this.eachData(data[key],keyList);
	    },
		//劫持对象原型
		reactiveArrayProto(data, keyList) {
			// 原始Array原型  
			var originalProto = Array.prototype,
				// 创建一个Array.prototype原型对象 
				newProto = Object.create(Array.prototype),
				that = this,
				result;
			// 劫持原型对象的方法
			['push', 'pop', 'shift', 'unshift', 'short', 'reverse', 'splice'].forEach((method) => {
				Object.defineProperty(newProto, method, {
					value: function () {
						//调用原始原型上的方法
						result = originalProto[method].apply(this, arguments);
						//处理数据并更新列队
						// console.log('that.data.'+keyList.join('.'))
						// eval('that.data.'+keyList.join('.')+'=cloneObj(this)');
						// console.log(keyList.join('.'))
						that.data.change && that.data.change.call(that.data);
						that.datas = cloneObj(that.data);
						that.eachData(data,keyList);
						// eval('that.data.'+keyList.join('.')+'=this');
						
						that.msg.update(keyList.join('.'));
						return result;
					}
				})
			});
			// 指定劫持后的原型对象
			data.__proto__ = newProto;
		},

	    //递归编译所有子节点
	    eachNode: function (el) {
	    	this.compile(el);
	        var e = el.childNodes;
	        if (e.length) {
	            for (var i = 0; i < e.length; i++) {
	            	this.compile(e[i]);
					//为了性能，遇到for和if不再遍历子级，直接交给该元素来处理后续
	                if(e[i].nodeType == 1 && !e[i].getAttribute('i-for') && !e[i].getAttribute('i-if')){
	                	this.eachNode(e[i]);
	                }
	            }
	        }
	    },

    	//编译
	    compile: function (node) {
	    	if(node.init) return;
	    	var that = this;
	        // 节点类型为元素
	        if (node.nodeType === 1) {
	            var attr = [];
	            for (var i = 0; i < node.attributes.length; i++) {
	            	attr.push({
	            		key:node.attributes[i].nodeName,
	            		value:node.attributes[i].nodeValue.trim()
	            	});
	            }
        		//处理for
        		var ifor = node.getAttribute('i-for');
	            if(ifor && ifor.length){
    				node.removeAttribute('i-for');
					node.itemNode = [];

					var hide = document.createComment('for');
					hide.node = node;
                	node.hide = hide;

                	//干掉源
                	node.parentNode.replaceChild(node.hide,node);

                	new thread(this, node, 'i-for', ifor);
                	node.init = true;
                	return;
        		}else{
					node.removeAttribute('i-item');
					node.removeAttribute('i-index');
				}
				var iif = node.getAttribute('i-if');
				if(iif && iif.length) {
					node.removeAttribute('i-if');
					node.itemNode = false;
					node.nodeC = node.cloneNode(true);

					var hide = document.createComment('if');
					hide.node = node;
                	node.hide = hide;

                	//干掉源
                	node.parentNode.replaceChild(node.hide,node);

                	new thread(this, node, 'i-if', iif);
                	node.init = true;
                	return;
				}
				
				//处理value值
	            if(node.value !== undefined && node.value.length && node.tagName !== 'TEXTAREA'){
					if(node.tagName === 'SELECT' || node.tagName === 'OPTION'){
						if(node.getAttribute('value')){
							new thread(this, node, 'value', node.value, 'attr');
						}
					}else{
						new thread(this, node, 'value', node.value, 'attr');
					}
        		}
        		//处理checked值
        		var checked = node.getAttribute('i-checked');
	            if(checked && checked.length){
    				node.removeAttribute('i-checked');
	                new thread(this, node, 'i-checked', checked);
        		}

	            // 解析属性
	            for (var i = 0; i < attr.length; i++) {
	                var key = attr[i].key; //属性名
	                var value = attr[i].value; //属性值
	                if(key == 'value' || key == 'checked' || key == 'i-checked'){
	                	break;
	                }
	                else if(key == 'i-model') {
						var vi = value;
						if (reg.test(vi)) {
							vi = RegExp.$1;
						}
						var r = vi.indexOf('.') > -1 || vi.indexOf('[') > -1 ? 1 : 0;

	                	if(node.type == 'text' || node.type == 'password' || node.tagName === 'TEXTAREA'){
	                		node.addEventListener('input', function (e) {
								if(r){
									that.reviseEnvRun(vi+'=$[1]',e.target.value);
								}else{
									eval('that.data.'+vi+'=e.target.value');
								}
		                    })
	                	}else if(node.type == 'checkbox'){
	                		if(!that.checkbox[vi]){
	                			if(that.data[vi] && that.data[vi].length){
	                				that.checkbox[vi] = cloneObj(that.data[vi]);
	                			}else{
	                				that.checkbox[vi] = [];
	                			}
	                		}

	                		//判断是否存在该值
            				if(node.checked && !that.checkbox[vi].includes(node.value)){
            					that.checkbox[vi].push(node.value);
            				}
            				//防止污染defineProperty，克隆是最保险的
            				that.data[vi] = cloneObj(that.checkbox[vi]);
	                		!function(v){
	                			node.addEventListener('click', function (e) {
		                			if(this.checked){
		                				if(!that.checkbox[v].includes(this.value)){
		                					that.checkbox[v].push(this.value);
			                			}
		                			}else{
		                				if(that.checkbox[v].includes(this.value)){
											var index = that.checkbox[v].indexOf(this.value);
											index > -1 && that.checkbox[v].splice(index, 1);
			                			}
		                			}
		                			that.data[v] = cloneObj(that.checkbox[v]);
			                    })
	                		}(vi);
	                	}else if(node.type == 'radio'){
	                		if(node.checked || node.getAttribute('checked')){
								if(r){
									that.reviseEnvRun(vi+'=$[1]',node.value);
								}else{
									eval('that.data.'+vi+'=node.value');
								}
	                		}
	                		!function(v){
		                		node.addEventListener('click', function (e) {
									if(r){
										that.reviseEnvRun(vi+'=$[1]',this.value);
									}else{
										eval('that.data.'+vi+'=this.value');
									}
			                    })
		                    }(vi);
	                	}else if(node.tagName == 'SELECT'){
							var selectValue = that.reviseEnv(vi);
							if(typeof selectValue == 'number' || selectValue.length){
								node.value = selectValue;
								//option中也会使用for，所以需要将该值传递过去处理成选中状态
								var child = node.children;
								if(child){
									for(var item of child){
										item.selectValue = selectValue;
									}
								}
							}else{
								if(r){
									that.reviseEnvRun(vi+'=$[1]',node.value);
								}else{
									eval('that.data.'+vi+'=node.value');
								}
							}
	                		node.addEventListener('change', function (e) {
								if(r){
									that.reviseEnvRun(vi+'=$[1]',this.value);
								}else{
									eval('that.data.'+vi+'=this.value');
								}
		                    })
	                	}
	                    // node.removeAttribute(key);
	                    new thread(this, node, key, vi);
	                }
	                else if(key == 'i-html') {
	                	node.removeAttribute(key);
	                	new thread(this, node, key, value);
	                }
	                else if(key == 'i-show') {
	                	node.removeAttribute(key);
	                	new thread(this, node, key, value);
	                }
	                else if (key.indexOf('i-on') !== -1) {
	                	var arr = key.split('.'),type=false,keys=key;
	                	if(arr.length>1){
	                		type = arr[1],keys = arr[0];
	                	}
	                	var eventType = keys.slice(4);
	                	var fn = function(e,f){
	                		type == 'stop' && sp(e);
	                		type == 'prevent' && pd(e);
	                		if(arr[2]){
	                			type = arr[1]+arr[2];
	                			if(type == 'stopprevent' || type == 'preventstop'){
		                			sp(e),pd(e);
		                		}
	                		}
	                		f()
	                	};
	                	if (reg.test(value)) {
                			var code = RegExp.$1;
	                		(function(code){
	                			node.addEventListener(eventType, function (e){
	                				setTimeout(()=>{
		                				fn(e,function(){
		                					that.reviseEnv(code);
		                				})
	                				}, 10);
	                			}, false)
	                		})(code);
				        }else{
		                    var cb = this.data[value];
		                    if (value && eventType && cb) {
		                    	node.addEventListener(eventType, function(e){
		                    		setTimeout(()=>{
		                    			fn(e,function(){
			                				cb.bind(that.data)(that.data,node,e);
			                			})
		                    		},10)
		                		}, false);
		                    }
				        }
				        node.removeAttribute(key);
	                }
	                else{
		                if (reg.test(value)) {
			                new thread(this, node, key, value, 'attr');
				        }
			        }
	            }
	        }
	        // 节点类型为text
	        if (node.nodeType === 3) {
	            if (reg.test(node.nodeValue)) {
	                new thread(this, node, false, node.nodeValue);
	            }
	        }
	        node.init = true;
	    },
	    getData:function(name){
			var that = this;
			// console.log('原始字符串', name);
	    	if(name && name.length){
				name = name.replace(/\[('|")/g,'_(L)_').replace(/('|")\]/g,'_(R)_');
				name = name.indexOf('"')>name.indexOf("'") ?
					name.replace(/'[^']+'/g,' ').replace(/"[^"]+"/g,' ') :
					name.replace(/"[^"]+"/g,' ').replace(/'[^']+'/g,' ');
				name = name.replace(/_\(L\)_/g,'.').replace(/_\(R\)_/g,'');

				//正则变量 
				name = name.match(/((?!\d)\w|\.|\[[^\]]+\])+/g);
				if(name){
					//将中括号的变量改为索引值，例如：list[index].name 处理为list[0].name
					name.forEach((v,k)=>{
						name[k] = v.replace(/\[([^\d]\w+)\]/g,function(a,b){
							b = b.trim();
							if (b.length) {
								return '['+that.reviseEnv(b)+']';
							}
							return a;
						})
					})
				}
				// console.log('处理变量后', name);
				name = ra(name);
				return name;
	    	}
			return [];
	    },
	    //环境变量
	    reviseEnv:function($str){
	    	var $v = '',$r = '';
			var $self = this;
	    	try {
	    		(function($this){
	    			$this.dataKey.forEach((k)=>{
			    		if(typeof $this.datas[k] == 'function'){
			    			$v += 'var '+k+'=$this.datas.'+k+'.bind($this.data);';
			    		}else{
			    			$v += 'var '+k+'=$this.datas.'+k+';';
			    		}
			    	});
			    	$v += $str ? $str : '';
		    		$r = eval($v);
	    		}).call(this.data,this);
			}
			catch(err) {
				console.log($self.msg.list);
				console.log($v);
			    console.log(err);
			}
			return $r == undefined ? '' : $r;
	    },
		//环境变量
	    reviseEnvRun:function($str){
	    	var $v = '',$r = '';
			var $self = this;
			var $ = arguments;
	    	try {
	    		(function($this){
	    			$this.dataKey.forEach((k)=>{
			    		if(typeof $this.data[k] == 'function'){
			    			$v += 'var '+k+'=$this.data.'+k+'.bind($this.data);';
			    		}else{
			    			$v += 'var '+k+'=$this.data.'+k+';';
			    		}
			    	});
			    	$v += $str ? $str : '';
		    		$r = eval($v);
	    		}).call(this.data,this);
			}
			catch(err) {
				console.log($self.msg.list);
				console.log($v);
			    console.log(err);
			}
			return $r == undefined ? '' : $r;
	    },
    };
    //初始化线程
    function thread(vm, node, key, value, type) {
        msg.target = this;
        this.vm = vm;
        this.node = node;
        this.key = key;
        this.value = value;
        this.content = value;
        this.type = type;
		var arr = node.nodeType === 3 ? this.vm.getData(node.nodeValue.match(reg).join('')) : this.vm.getData(value);
		this.update();
		arr.forEach((v)=>{
			this.v = v;
			this.vm.msg.addList(this,v);
		});
        
        msg.target = null;
    }
    thread.prototype = {
        update: function () {
        	// console.log(this.vm.msg.list)
            var that = this;
            if (this.key == 'i-for'){
				var list;
				var value = this.value;
				if (reg.test(this.value)) {
					var code = RegExp.$1;
					value = code;
					list = this.vm.reviseEnv(code);
				}else{
					list = this.vm.data[this.value];
				}
				if(!list || !list.length) list = []; //防止报错

				//清空所有for循环中的元素节点，包括消息列队
				var items = false;
				var itemNodeList = [];
				for(var i=0;i<this.node.itemNode.length;i++){
					
					if(isObjectEqual(this.node.itemNode[i].data) == isObjectEqual(list[i])){
						items = i;
						itemNodeList.push(this.node.itemNode[i]);
						continue;
					}
					
					//因为if会创建占位元素，从而加入到消息列队中
					this.vm.msg.delList(this.node.itemNode[i]);
					this.vm.msg.delList(this.node.itemNode[i].itemNode);
				}
				this.node.itemNode = itemNodeList;
				if(typeof list == 'object'){
					var itemNode = this.node.cloneNode(true);

					//获取定义的item和index
					var itemName = itemNode.getAttribute('i-item'), indexName = itemNode.getAttribute('i-index');
					itemName = itemName && itemName.length > 0 ? itemName : 'item';
					indexName = indexName && indexName.length > 0 ? indexName : 'index';

					var itemReg = new RegExp('(?!\\.)'+itemName, 'g'), indexReg = new RegExp('(?!\\.)'+indexName+'(?!\\.)', 'g');
					// var frag = document.createDocumentFragment();

					//处理所有的attr
					var attr = [];
					for (var s = 0; s < itemNode.attributes.length; s++) {
						let v = itemNode.attributes[s].nodeValue;
						if(reg.test(v)){
							attr.push({
								k:itemNode.attributes[s].nodeName,
								v:v
							})
						}
					}
					items = items !== false ? items+1:0;
					for(let i=items;i<list.length;i++){
						//克隆节点
						var node = this.node.cloneNode(true);
						node.selectValue = this.node.selectValue;
						node.data = list[i];
						for (var s = 0; s < attr.length; s++) {
							node.setAttribute(attr[s].k, attr[s].v.replace(reg, (a)=>{
								if (a.length) {
									return a.replace(itemReg, value+'['+i+']').replace(indexReg, i);
								}
								return a;
							}));
						}
						//先判断是否存在if，如果条件不允许的话无需创建node节点了，避免内存开销
						// var ifValue = node.getAttribute('i-if');
						// if(ifValue){
						// 	// node.removeAttribute('i-if');
						// 	reg.test(ifValue);
						// 	ifValue = this.vm.reviseEnv(RegExp.$1);
						// 	console.log(ifValue,typeof ifValue)
						// 	if(ifValue === 'false' || !Boolean(ifValue)){
						// 		continue;
						// 	}
						// }
						
						node.innerHTML = node.innerHTML.replace(reg, (a)=>{
							if (a.length) {
								return a.replace(itemReg, value+'['+i+']').replace(indexReg, i);
							}
							return a;
						});
						this.node.itemNode.push(node);
						// frag.appendChild(node);
						this.node.hide.parentNode.insertBefore(node,this.node.hide);
						this.vm.eachNode(node);
						
					}
				}
				return;
			}

			if (this.key == 'i-if') {
            	//清空元素节点，包括消息列队
				if(this.node.itemNode){
					var value = this.vm.reviseEnv(this.value.match(reg)[0]);
					if(!Boolean(value)){
						this.vm.msg.delList(this.node.itemNode);
						this.node.itemNode = false;
					}
					return;
				} 
				this.node.itemNode = false;
				var value = this.vm.reviseEnv(this.value.match(reg)[0]);
				if(Boolean(value)){
					//克隆元素
					var itemNode = this.node.nodeC.cloneNode(true);
					//重新赋值
					this.node.itemNode = itemNode;
					//插入元素
					this.node.hide.parentNode.insertBefore(itemNode,this.node.hide);
					//遍历处理
					this.vm.eachNode(itemNode);
				}
				return;
			}

            if (this.node.nodeType == 1) {

				if(this.type == 'attr'){
					var value = this.content.replace(reg, function(a, b){
						b = b.trim();
						if (b.length) {
							return that.vm.reviseEnv(b);
						}
						return a;
					});
					this.node.setAttribute(this.key,value);
					if(this.node.selectValue != undefined){
						if(value.toString() == this.node.selectValue.toString()){
							this.node.selected = true;
						}
					}
					return;
				}
				else if (this.key == 'i-show') {
					reg.test(this.value)
					var value = this.vm.reviseEnv(RegExp.$1);
					this.node.style.display = Boolean(value) ? 'initial' : 'none';
					return;
				}
				else if (this.key == 'i-checked') {
					var value = this.value;
					if (reg.test(this.value)) {
						value = this.vm.reviseEnv(RegExp.$1);
					}
					this.node.checked = Boolean(value);
					return;
				}
				else if (this.key == 'i-html') {
                    this.node.innerHTML = this.text;
                }
				
				var v = this.value;
				v = v.replace(reg, (a, b) => {
					b = b.trim();
					if (b.length) {
						return this.vm.reviseEnv(b);
					}
					return a;
				});
				try {
					this.vm.reviseEnvRun('$[1].text='+v,this);
				}
				catch(err) {
					this.text = '';
				}

                if (this.node.tagName == 'INPUT') {
                	if(this.node.type == 'checkbox'){
                		if(this.vm.data[this.value].includes(this.node.value)){
                			this.node.checked = true;
                		}
                		return;
                	}
                	if(this.node.type == 'radio'){
                		if(this.node.value === this.vm.data[this.value]){
                			this.node.checked = true;
                		}
                	}else{
						this.node.value = this.text;
                	}
                }
                else if (this.node.tagName == 'TEXTAREA') {
                	this.node.value = this.text;
                }
                else if (this.node.tagName == 'SELECT') {
                	this.node.value = this.text;
                }

                
            }else if(this.node.nodeType == 3){
				this.text = this.content.replace(reg, (a, b) => {
                    b = b.trim();
                    if (b.length) {
                    	return this.vm.reviseEnv(b);
                    }
                    return a;
                });


            	this.node.nodeValue = this.text;
            }
        }
    }
    return new iceView(options, msgList);
};